import java.util.Scanner;

public class demo2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            String s = scan.nextLine();
            while(s.length() > 1){
                int temp = 0;
                for(int i = 0; i < s.length(); i++){
                    temp += (s.charAt(i)-'0');
                }
                s = String.valueOf(temp);
            }
            System.out.println(Integer.parseInt(s));

        }
    }
}
